package com.sxj.shop.util;

import com.sxj.shop.exception.MD5ErrorException;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class MD5Util {

    /**
     * 使用MD5对密码进行加密
     * @param password
     * @return
     */
    public static String md5(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bs = md.digest(password.getBytes());
            return Base64.getEncoder().encodeToString(bs);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new MD5ErrorException("MD5加密出错");
        }
    }

}
